

    import { defineConfig,loadEnv } from "vite";
    import vue from "@vitejs/plugin-vue";
    import { resolve } from "path";
    import viteSvgIcons from "vite-plugin-svg-icons";
    
    export default defineConfig(({ mode }) => {
      const env = loadEnv(mode, process.cwd())
      let config={
      base: mode === 'local' ? '/' : './',
      define: {
        'process.env': env
      },
      build: {
        terserOptions: {
          compress: {
            drop_console: true,
            drop_debugger: true,
          },
        },
      }, 
      plugins: [
        vue(),
      
        viteSvgIcons({
          // 指定需要缓存的图标文件夹
          iconDirs: [resolve(process.cwd(), "src/assets/icon/svg")],
          // 指定symbolId格式
          symbolId: "[name]",
        }),
      
      ],
      // 文件夹别名 @ 为src目录
      resolve: {
        alias: [
          {
            find: "@",
            replacement: resolve(__dirname, "src"),
          },
        ],
        extensions: [".vue", ".js"],
      },
    
      css: {
        preprocessorOptions: {
          scss: {
            additionalData: '@use "@/assets/scss/colorUI.scss" as *;',
          },
          less:{
            additionalData: `
            @use "@/assets/styles/variables.less";
          `
          }
        },
      },
    
      server: {
        port: 3000, //端口号
        open: true, //是否自动在浏览器打开
        host: '0.0.0.0',
        outDir: 'dist', // 打包构建输出路径，默认 dist ，如果路径存在，构建之前会被删除
        proxy: {
          // 本地开发环境通过代理实现跨域，生产环境使用 nginx 转发
          '^/studio': {
            target: 'http://192.168.1.85:8082', // 测试环境接口
            // target: 'http://192.168.1.79:8083', // 演示环境接口
            changeOrigin: true,
            // rewrite: (p) => p.replace(/^\//, '')
          },
          '/prod-api':{
            target: 'http://vue.ruoyi.vip/', // 
            changeOrigin: true,
            // rewrite: (p) => p.replace(/^\//, '')
          }

        },
        fs: {
          // 可以为项目根目录的上一级提供服务
          allow: ['..'],
        },
      },
    }
    return config
    });
    
  